import Vue from 'vue'
import App from './App.vue'

Vue.config.productionTip = false

import Find from './views/Find.vue'
import My from './views/My.vue'
import Part from './views/Part.vue'
import SongList from './views/Second/SongList.vue'
import Ranking from './views/Second/Ranking.vue'
import Recommend from './views/Second/Recommend.vue'
import NotFound from './views/NotFound.vue'

import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routes = [{
        path: '/',
        redirect: '/find'
    },
    {
        name: 'Find',
        path: '/find',
        component: Find,
        children: [{
                name: 'SongList',
                path: 'songlist',
                component: SongList
            },
            {
                name: 'Ranking',
                path: 'ranking',
                component: Ranking
            },
            {
                name: 'Recommend',
                path: 'recommend',
                component: Recommend
            },

        ]
    },
    {
        name: 'My',
        path: '/my',
        component: My
    },
    {
        name: 'Part',
        path: '/part',
        component: Part
    },
    {
        name: 'Part',
        path: '/part/:name/:age',
        component: Part
    },
    {
        path: '*',
        component: NotFound
    }
]
const router = new VueRouter({ routes, mode: "history" })


let isLogin = false
router.beforeEach((to, from, next) => {
    if (to.path === '/my' && isLogin == false) {
        alert('你没登录')
        return next(false)
    }
    next()
})


new Vue({
    render: h => h(App),
    router
}).$mount('#app')